<template>
  <div class="preset-template-grid">
    <div class="grid-layout">
      <div 
        v-for="template in templates" 
        :key="template.prompt" 
        @click="$emit('select', template)"
        class="card card-glass cursor-pointer preset-card transform transition-all duration-300 hover:scale-102 hover:-translate-y-1"
      >
        <div class="p-5 flex flex-col h-full">
          <div class="card-header">
            <h3 class="card-title">{{ template.prompt }}</h3>
          </div>
          
          <div class="flex-grow flex items-center justify-center p-3">
            <div class="svg-container-wrapper">
              <div class="svg-container" v-html="template.svg"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'PresetTemplateGrid',
  props: {
    templates: {
      type: Array,
      default: () => []
    }
  },
  emits: ['select']
}
</script>

<style>
.preset-template-grid {
  width: 100%;
}

.grid-layout {
  display: grid;
  grid-template-columns: repeat(1, 1fr);
  gap: 2rem;
  margin-bottom: 3rem;
}

@media (min-width: 768px) {
  .grid-layout {
    grid-template-columns: repeat(2, 1fr);
  }
}

.preset-card {
  cursor: pointer;
  overflow: hidden;
  min-height: 380px;
  border-radius: var(--radius-xl);
  transition: all 0.3s ease;
  width: 100%;
}

.preset-card:hover {
  box-shadow: var(--shadow-md);
}

.card-header {

  position: relative;
  display: flex;
  align-items: center;
}

.card-header::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -1px;
  width: 40px;
  height: 3px;
  background: linear-gradient(to right, var(--color-primary, #3b82f6), var(--color-accent, #ec4899));
  border-radius: 3px;
}

.card-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-gray-800, #1f2937);
  line-height: 1.4;
  letter-spacing: -0.01em;
  padding-left: 0.5rem;
}

@media (prefers-color-scheme: dark) {
  .card-title {
    color: var(--color-gray-100, #f3f4f6);
  }
  
  .card-header {
    border-bottom-color: rgba(55, 65, 81, 0.6);
  }
}

.svg-container-wrapper {
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
}

.svg-container {
  margin: 8px 0px;
  width: 100%;
  position: relative;
  padding-top: 150%; /* 保持2:3的宽高比 */
}

.svg-container svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.preset-card {
  opacity: 0;
  animation: fadeIn 0.5s ease-out forwards;
}

.preset-card:nth-child(1) { animation-delay: 0.05s; }
.preset-card:nth-child(2) { animation-delay: 0.1s; }
.preset-card:nth-child(3) { animation-delay: 0.15s; }
.preset-card:nth-child(4) { animation-delay: 0.2s; }
.preset-card:nth-child(5) { animation-delay: 0.25s; }
.preset-card:nth-child(6) { animation-delay: 0.3s; }
.preset-card:nth-child(7) { animation-delay: 0.35s; }
.preset-card:nth-child(8) { animation-delay: 0.4s; }

.hover\:scale-102:hover {
  transform: scale(1.02);
}

/* 针对移动设备调整布局 */
@media (max-width: 640px) {
  .preset-card {
    min-height: 320px;
  }
  
  .card-title {
    font-size: 1.125rem;
  }
}
</style> 